﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WorkOrder.Business;

namespace WorkOrder
{
    public partial class queryChangeover : System.Web.UI.Page
    {
        Business_Table_Changeover B_T_C = new Business_Table_Changeover();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null || Session["UserID"].ToString() == "")
            {
                Session.Clear();
                ClientScript.RegisterClientScriptBlock(this.GetType(), "windowhref", "<script type='text/javascript'>alert('对不起，您还没有登录系统！');window.parent.location.href='../login.aspx';</script>");
            }
        }
        protected void btnSearch_ServerClick(object sender, EventArgs e)
        {
            if (txtSTART_DATE.Value.Trim() != "" && txtEND_DATE.Value.Trim() != "")
            {
                string sqlstr1 = "select town_name as 镇区,(COUNT(cast(changeover_id as varchar(40)))) as 割接单数量 into #T " +
                    "from (select A.changeover_id,B.town_name from Table_Changeover as A,Table_Town as B where A.town_id=B.town_id and " +
                    "A.first_cute_time between '" + txtSTART_DATE.Value.Trim() + " 0:0:0' and '" + txtEND_DATE.Value.Trim() + " 23:59:59') as A group by town_name;" +
                    "select * from #T union select '合计',SUM(割接单数量) from #T order by 割接单数量;drop table #T;";
                string sqlstr2 = "select area_name as 区域,(COUNT(cast(changeover_id as varchar(40)))) as 割接单数量 into #T " +
                    "from (select A.changeover_id,B.area_name from Table_Changeover as A,Table_Area as B where A.area_id=B.area_id and " +
                    "A.first_cute_time between '" + txtSTART_DATE.Value.Trim() + " 0:0:0' and '" + txtEND_DATE.Value.Trim() + " 23:59:59') as A group by area_name;" +
                    "select * from #T union select '合计',SUM(割接单数量) from #T order by 割接单数量;drop table #T;";
                string sqlstr3 = "select product_name as 产品类型,(COUNT(cast(changeover_id as varchar(40)))) as 割接单数量 into #T " +
                    "from (select A.changeover_id,B.product_name from Table_Changeover as A,Table_Product as B where A.product_id=B.product_id and " +
                    "A.first_cute_time between '" + txtSTART_DATE.Value.Trim() + " 0:0:0' and '" + txtEND_DATE.Value.Trim() + " 23:59:59') as A group by product_name;" +
                    "select * from #T union select '合计',SUM(割接单数量) from #T order by 割接单数量;drop table #T;";
                GridView1.DataSource = B_T_C.GetDatas(sqlstr1);
                GridView1.DataBind();
                GridView2.DataSource = B_T_C.GetDatas(sqlstr2);
                GridView2.DataBind();
                GridView3.DataSource = B_T_C.GetDatas(sqlstr3);
                GridView3.DataBind();
            }
        }
        protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex >= 0)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor,this.style.background='#ffe3a0'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
        }
    }
}
